package gsw.demo.bean;

import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;

import java.util.ArrayList;
import java.util.List;

/**
 * JavaBean：用于测试json框架
 */
@JSONType(typeKey = "Parent")
public class Parent {
    String name;

    public Parent() {
    }

    public Parent(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }

    /**
     * JavaBean：用于测试json框架
     */
    @JSONType(ignores = {"name"}, orders = {"list", "age", "childs", "name"}, typeName = "Child")
    public static class Child extends Parent {
        private int age;
        public List<String> list;

        public List<Child> childs;

        public Child() {

        }

        /**
         * 指定FastJson反序列化构造函数
         *
         * @param name
         * @param age
         */
        @JSONCreator
        public Child(@JSONField(name = "name") String name, @JSONField(name = "age") int age) {
            super(name);
            this.age = age;
            list = new ArrayList<>();
            list.add("1");
            list.add("2");
        }

        public int getTest() {
            return 1;
        }

        //非公有属性需要有
        public void setAge(int age) {
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        @Override
        public String toString() {
            return "Child{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", list=" + list +
                    ", childs=" + childs +
                    '}';
        }
    }
}
